%% term_U_grad_Wold_Psi
function matrix_A = term_U_grad_Wold_Psi(mesh, fespace, Wold)
Nb1 = fespace.Nb;
Nlb1 = fespace.Nlb;
rows = zeros(mesh.Ne*Nlb1*Nlb1,1);
cols = rows;
val1 = rows;
val2 = rows;
flag = 1;
for n = 1:mesh.Ne
    V = mesh.node(mesh.elem(n,:),:);
    [int_points_loc, int_weights_loc] = integral_loc(V, "2d");
    phi = basis_loc(V, int_points_loc(:,1), int_points_loc(:,2), fespace.basis_type, "x");
    phix = basis_loc(V, int_points_loc(:,1), int_points_loc(:,2), fespace.basis_type, "dx");
    phiy = basis_loc(V, int_points_loc(:,1), int_points_loc(:,2), fespace.basis_type, "dy");
    w3x = phix * Wold(fespace.elem(n,:));
    w3y = phiy * Wold(fespace.elem(n,:));
    for i = 1:Nlb1
        for j = 1:Nlb1
            f1 = phi(:,j).*w3x.*phi(:,i);
            f2 = phi(:,j).*w3y.*phi(:,i);
            r1 = int_weights_loc * f1;
            r2 = int_weights_loc * f2;
            rows(flag) = fespace.elem(n,i);
            cols(flag) = fespace.elem(n,j);
            val1(flag) = r1;
            val2(flag) = r2;
            flag = flag + 1;
        end
    end
end
A1 = sparse(rows, cols, val1, Nb1, Nb1);
A2 = sparse(rows, cols, val2, Nb1, Nb1);
matrix_A = [A1, A2];
end